package assignment2;

import java.io.BufferedReader;
import java.io.IOException;
import java.net.Socket;

/**
 * @DESCRIPATION
 * @AUTHOR 戴超
 * @DATE 2018/6/19
 **/
public class Receiver implements Runnable {
    BufferedReader br = null;
    Socket socket = null;

    public Receiver(BufferedReader br, Socket socket) {
        this.br = br;
        this.socket = socket;
    }

    @Override
    public void run() {
        while (socket.isConnected() && socket.isBound() && !socket.isClosed()) {
            String msg = null;
            try {
                msg = br.readLine();
                if (msg != null && msg.trim().length() > 0) {
                    if ("exit".equals(msg)) {
                        socket.close();
                    }
                }
                System.out.println("他说:" + msg);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

